package com.parse.utils;
import com.parse.dto.Product;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

public class ExcelUtil {
	
	public static void createWorkBook(List<Product> list) {
	      //TODO:keysList colsList的第0个为汇总信息  第1个为漏洞详细信息
	        // 创建excel工作簿
	        HSSFWorkbook wb = new HSSFWorkbook();
	        // 创建sheet（页），用于展示汇总情况
	        HSSFSheet sheet = wb.createSheet("商品信息");
		HSSFRow headRow = sheet.createRow(0);
		headRow.createCell(0).setCellValue("品牌");
		headRow.createCell(1).setCellValue("商品名称");
		headRow.createCell(2).setCellValue("价格");
		for(int i=1;i<list.size();i++){
	    	HSSFRow row = sheet.createRow(i);
	    	HSSFCell cell = row.createCell(0);
	    	cell.setCellValue(list.get(i).getBrandName());
	    	row.createCell(1).setCellValue(list.get(i).getProName());
	    	row.createCell(2).setCellValue(list.get(i).getPrice());
	    	//HSSFCell cell2 = row.createCell(1);
	    	//cell2.setCellValue(list.get(i).getPrice());
	    	//其他依次类推
	    }
		  //创建excel文件
	    File file=new File("d://poi.xlsx");
	    
	    FileOutputStream outputStream;
		try {
			outputStream = new FileOutputStream(file);
		    wb.write(outputStream);
		} catch (Exception e) {
			e.printStackTrace();
		}
	   
	}
}
